#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5 + 10;
int a[N];
int n, k;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> k;
		bool flag = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (i != 1 && a[i] != a[i - 1])flag = 1;
		}
		if (k == 1) {
			cout << "YES" << endl;
			continue;
		}
		if (n == 2) {
			if (a[1] != a[2])cout << "NO" << endl;
			else cout << "YES" << endl;
			continue;
		}
		if (!flag) {
			cout << "YES" << endl;
			continue;
		}
		if (k == 2) {
			if (a[1] == a[n]) {
				cout << "YES" << endl;
				continue;
			}
		}
		int v1 = a[1], v2 = a[n];
		int cnt1 = 1, cnt2 = 1;
		int idx1 = 0, idx2 = 0;
		for (int i = 2; i <= n; i++) {
			if (a[i] == v1) {
				cnt1++;
				if (cnt1 >= k) {
					idx1 = i;
					break;
				}
			}
		}
		for (int i = n - 1; i >= 1; i--) {
			if (a[i] == v2) {
				cnt2++;
				if (cnt2 >= k) {
					idx2 = i;
					break;
				}
			}
		}
		//cout << "idx1==" << idx1 << endl;
		//cout << "idx2==" << idx2 << endl;
		if (!idx1 || !idx2) {
			cout << "NO" << endl;
			continue;
		}
		if (idx1 == n || idx2 == 1) {
			cout << "YES" << endl;
			continue;
		}
		if (idx1 < idx2)cout << "YES" << endl;
		else if (idx1 == idx2) {
			if (cnt1 + cnt2 - 1 >= k)cout << "YES" << endl;
			else cout << "NO" << endl;
		}
		else {
			if (a[1]==a[n] && cnt1 + cnt2 - 1 >= k)cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}